//
//  ZLNavigationViewController.swift
//  ZLWeibo
//
//  Created by zhanglongtao on 16/12/15.
//  Copyright © 2016年 hanju001. All rights reserved.
//

import UIKit

class ZLNavigationViewController: UINavigationController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        
        //隐藏默认的Bar
        navigationBar.isHidden = true
        
        
    }

    //重写push方法 viewController被push的控制器 设置左侧按钮为返回按钮
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        
        if childViewControllers.count > 0
        {
            //如果不是栈底控制器  更控制器不需要处理
            viewController.hidesBottomBarWhenPushed = true
            
            //判断控制器的类型
            if let vc = viewController as? ZLBaseViewController
            {
                var title = "返回";
                //判断控制器的级数
                if childViewControllers.count == 1{
                    //title等于首页标题
                    title = childViewControllers.first?.title ?? "返回"
                }
                //自定义item
                vc.navItem.leftBarButtonItem = UIBarButtonItem(title: title, fontsize: 16, target: self, action: #selector(popToParent), isBackButton: true)
            }
            

        }
        
        super.pushViewController(viewController, animated: animated)
        
    }
    func popToParent() -> () {
        
        popViewController(animated: true)
        
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
